package com.firefly.web.controller.admin.cms;

import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.cms.TypeDto;
import com.firefly.dao.dto.cms.TypeSortDto;
import com.firefly.dao.vo.cms.TypeVo;
import com.firefly.service.command.cms.TypeCommand;
import com.firefly.service.query.cms.TypeQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.Map;

/**
 * (Types)表控制层
 *
 * @author makejava
 * @since 2022-08-02 08:57:45
 */
@ConsoleApiRestController("/type")
public class TypeController {
	private final TypeQuery typeQuery;
	private final TypeCommand typeCommand;
	@Autowired
	public TypeController(TypeQuery typeQuery, TypeCommand typeCommand){
		this.typeQuery = typeQuery;
		this.typeCommand = typeCommand;
	}
    @GetMapping("/list")
    public List<Map> getList() {
        return typeQuery.tree();
    }
    @GetMapping("/detail")
	public TypeVo getDetail(@Validated(CommonDto.showDetail.class) CommonDto request) {
		return typeQuery.getDetailById(request.detailId);
	}

	@PostMapping("/create")
	public Boolean postCreate(@Validated(TypeDto.create.class) TypeDto request) {
		return typeCommand.create(request);
	}

	@PostMapping("/update")
	public Boolean postUpdate(@Validated(TypeDto.update.class) TypeDto request) {
		return typeCommand.updateName(request);
	}

	@PostMapping("/sort")
	public Boolean postSort(@Validated TypeSortDto request) {
		return typeCommand.sort(request);
	}
    @PostMapping("/remove")
	public Boolean postRemove(@Validated(CommonDto.showDetail.class) CommonDto request) {
		return typeCommand.remove(request.getDetailId());
	}
}

